package com.example.listtest_1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.listtest_1.R;
import com.example.listtest_1.bean.Student;

import java.util.List;

public class StudentArrayAdapter extends ArrayAdapter<Student> {

    public StudentArrayAdapter(@NonNull Context context, List<Student> data) {
        super(context, 0,data);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Student student=getItem(position);
        if (convertView ==null){
            convertView= LayoutInflater.from(getContext()).inflate(
                    R.layout.array_adapter_item,parent,false);
        }
        TextView nameText=convertView.findViewById(R.id.name);
        TextView numberText=convertView.findViewById(R.id.number);
        if (student !=null){
            nameText.setText(student.getName());
            numberText.setText(student.getNumber());
            convertView.setTag(student);
        }
        return convertView;

    }
}
